home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / maze.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  4.1 KB  |  163 lines

  1. ; AisleRiot - maze.scm
  2. ; Copyright (C) 2000 Matthew Wilcox <willy@linuxcare.com>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define card '())
  20.  
  21. (define (add-line)
  22.   (add-normal-slot '())
  23.   (add-normal-slot '())
  24.   (add-normal-slot '())
  25.   (add-normal-slot '())
  26.   (add-normal-slot '())
  27.   (add-normal-slot '())
  28.   (add-normal-slot '())
  29.   (add-normal-slot '())
  30.   (add-normal-slot '())
  31. )
  32.  
  33. (define (new-game)
  34.   (initialize-playing-area)
  35.   (set-ace-low)
  36.   (make-standard-deck)
  37.   (shuffle-deck)
  38.  
  39.   (add-normal-slot DECK)
  40.   (add-normal-slot '())
  41.   (add-normal-slot '())
  42.   (add-normal-slot '())
  43.   (add-normal-slot '())
  44.   (add-normal-slot '())
  45.   (add-normal-slot '())
  46.   (add-normal-slot '())
  47.   (add-normal-slot '())
  48.   (add-carriage-return-slot)
  49.  
  50.   (add-line)
  51.   (add-carriage-return-slot)
  52.   (add-line)
  53.   (add-carriage-return-slot)
  54.   (add-line)
  55.   (add-carriage-return-slot)
  56.   (add-line)
  57.   (add-carriage-return-slot)
  58.   (add-line)
  59.  
  60.   (deal-cards-face-up 0 '(1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 18 19
  61.                 20 21 22 23 24 25 26 27 28 29 30 31 32 33 
  62.                 34 35 36 37 38 39 40 41 42 43 44 45 46 47 
  63.                 48 49 50 51 52 53))
  64.  
  65.   (make-visible-top-card 0)
  66.   (eliminate-kings 53)
  67.  
  68.   (calculate-score)
  69.  
  70.   (list 9 6))
  71.  
  72. (define (eliminate-kings slot)
  73.   (and (not (empty-slot? slot))
  74.        (= (get-value (get-top-card slot)) king)
  75.        (remove-card slot))
  76.   (and (> slot 0)
  77.        (eliminate-kings (- slot 1))))
  78.  
  79. (define (button-pressed slot-id card-list)
  80.   #t)
  81.  
  82. (define (suit-next? first second)
  83.   (and (= (get-suit first)
  84.       (get-suit second))
  85.        (= (+ 1 (get-value first))
  86.       (get-value second))))
  87.  
  88. (define (card-next? lower higher)
  89.   (or (and (= ace (get-value higher))
  90.        (= queen (get-value lower)))
  91.       (suit-next? lower higher)))
  92.  
  93. (define (button-released start-slot card-list end-slot)
  94.   (and (droppable? start-slot card-list end-slot)
  95.        (add-card! end-slot (car card-list))))
  96.  
  97. (define (droppable? start-slot card-list end-slot)
  98.   (set! card (car card-list))
  99.   (and (not (= start-slot end-slot))
  100.        (empty-slot? end-slot)
  101.        (or (if (= end-slot 0)
  102.            (= ace (get-value card))
  103.            (and (not (empty-slot? (- end-slot 1)))
  104.             (card-next? (get-top-card (1- end-slot)) card)))
  105.        (if (= end-slot 53)
  106.            (= queen (get-value card))
  107.            (and (not (empty-slot? (1+ end-slot)))
  108.             (card-next? card (get-top-card (1+ end-slot))))))))
  109.  
  110. (define (button-clicked slot-id)
  111.   #f)
  112.  
  113. (define (button-double-clicked slot-id)
  114.   #f)
  115.  
  116. (define (get-full-card slot)
  117.   (if (empty-slot? slot)
  118.       (get-full-card (1+ slot))
  119.       (get-top-card slot)))
  120.  
  121. (define (calculate-score)
  122.   (set! card (get-full-card 0))
  123.   (if (= (get-value card) ace)
  124.       (set-score! 1)
  125.       (set-score! 0))
  126.   (calculate-score-helper 1 card)
  127.   (= (get-score) 48) ; 48 cards in the pack
  128. )
  129.  
  130. (define (calculate-score-helper slot prev)
  131.   (or (= slot 54)
  132.       (and (empty-slot? slot)
  133.        (calculate-score-helper (1+ slot) prev))
  134.       (and (set! card (get-top-card slot))
  135.        (card-next? prev card)
  136.        (add-to-score! 1)
  137.        #f)
  138.       (calculate-score-helper (1+ slot) card)))
  139.  
  140. (define (game-won)
  141.   (calculate-score))
  142.  
  143. (define (game-over)
  144.   (not (game-won)))
  145.  
  146. (define (get-hint)
  147.   (list 0 (_"Aim to place the suits in the order which fits the current layout most naturally.")))
  148.  
  149. (define (get-options) 
  150.   #f)
  151.  
  152. (define (apply-options options) 
  153.   #f)
  154.  
  155. (define (timeout) 
  156.   #f)
  157.  
  158. (set-features droppable-feature)
  159.  
  160. (set-lambda new-game button-pressed button-released button-clicked
  161. button-double-clicked game-over game-won get-hint get-options
  162. apply-options timeout droppable?)
  163.